<%@page import="java.util.LinkedHashMap"%>
<%@page import="com.shsh.safemanage.model.PostcheckMonthQualityReport.ShiyebuReport.ShiyebuReportCell"%>
<%@page import="com.shsh.safemanage.model.PostCheck"%>
<%@page import="com.shsh.safemanage.model.PostcheckMonthQualityReport.ShiyebuReport"%>
<%@page import="com.shsh.safemanage.util.Util"%>
<%@page import="com.shsh.safemanage.dao.PostCheckDao"%>
<%@page import="com.shsh.safemanage.dao.DaoCreator"%>
<%@page import="com.shsh.safemanage.action.ActionCreator"%>
<%@page import="com.shsh.safemanage.util.Constants"%>
<%@page import="com.shsh.safemanage.util.RequestUtil"%>
<%@page import="com.shsh.safemanage.action.PostcheckReportAction"%>
<%@page import="com.shsh.safemanage.model.PostcheckMonthQualityReport"%>
<%@page import="com.shsh.safemanage.model.Department1"%>
<%@page import="java.util.Map"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<%
	{
	session.removeAttribute(Constants.SESSION_POSTCHECK_MONTH_QUALITY_REPORT);

	Integer year = RequestUtil.getParameter(request, Constants.REQUEST_PARAMETER_YEAR, 0);
	Integer month = RequestUtil.getParameter(request, Constants.REQUEST_PARAMETER_MONTH, 0);

	PostcheckReportAction reportAction = ActionCreator.createPostcheckReportAction();
	PostCheckDao postcheckDao = DaoCreator.createPostCheckDao();

	PostcheckMonthQualityReport report = postcheckDao.getMonthQualityReport(year, month);

	if(report == null){
		boolean isSuccess = reportAction.generateMonthQualityReport(request);
		if(isSuccess) {
			report = (PostcheckMonthQualityReport) request.getAttribute(Constants.REQUEST_ATTRIBUTE_POSTCHECK_MONTH_QUALITY_REPORT);
		} else {
			return;
		}
	}
	request.setAttribute(Constants.REQUEST_ATTRIBUTE_POSTCHECK_MONTH_QUALITY_REPORT, report);
	session.setAttribute(Constants.SESSION_POSTCHECK_MONTH_QUALITY_REPORT, report);
	
	Map<Long, Department1> shiyebuList = report.getShiyebuList();
	Map<Long, PostcheckMonthQualityReport.ShiyebuReport> shiyebuReportMap = report.getShiyebuReportMap();
	int tableWidth = 240 + shiyebuList.size() * 60;
%>

<div class="content" style="width:1100px;">
	<div class="tt">《作业部（业务中心）岗检质量评价表》</div>
	<div style="width:97%;margin-left: 10px;font-weight:bold;font-size:20; ">
	<span style="margin-right: 20px;float:right;">
		月份：<%=report.getYear() %>年<%=report.getMonth() %>月
	</span>
	</div>
	
	<br />
	
	<table border="1" style="align:center; margin-left: 6px;" width="<%=tableWidth+130%>">
		<tr>
			<td colspan="4" style="text-align:center;" class="td3" width="240">
			单位
			</td>
<%
for (Department1 shiyebu: shiyebuList.values()) {
%>
			<td colspan="2" style="text-align:center" class="td3" width="60">
			<%=Util.getDisplay(shiyebu.getDepartmentName(), "&nbsp;") %>
			</td>
<%
}
%>
		</tr>
		<tr>
			<td colspan="4" style="text-align:center;" class="td3">
			工作天数
			</td>
<%
for (Department1 shiyebu: shiyebuList.values()) {
%>
			<td colspan="2" style="text-align:center;">
			<%=Util.getDisplay(report.getWorkingDay(), "&nbsp;") %>
			</td>
<%
}
%>
		</tr>
		<tr>
			<td colspan="4" style="text-align:center;" class="td3">
			参加岗检人数
			</td>
<%
for (Department1 shiyebu: shiyebuList.values()) {
	ShiyebuReport shiyebuReport = shiyebuReportMap.get(shiyebu.getId());	
%>
			<td colspan="2" style="text-align:center;">
				<input type="text" id="workerCount<%=shiyebu.getId() %>" name="workerCount<%=shiyebu.getId() %>" style="width:25px;" value="<%=shiyebuReport==null||shiyebuReport.getWorkerCount()==null?"":shiyebuReport.getWorkerCount()%>"/>
			</td>
<%
}
%>
		</tr>
		<tr>
			<td colspan="4" style="text-align:center;" class="td3">
			所属单元数
			</td>
<%
for (Department1 shiyebu: shiyebuList.values()) {
	ShiyebuReport shiyebuReport = shiyebuReportMap.get(shiyebu.getId());	
%>
			<td colspan="2" style="text-align:center;">
				<input type="text" id="unitCount<%=shiyebu.getId() %>" name="unitCount<%=shiyebu.getId() %>" style="width:25px;" value="<%=shiyebuReport==null||shiyebuReport.getUnitCount()==null?"":shiyebuReport.getUnitCount()%>"/>
			</td>
<%
}
%>
		</tr>
		<tr>
			<td colspan="4" style="text-align:center;" class="td3">
			应参加岗检人次数
			</td>
<%
for (Department1 shiyebu: shiyebuList.values()) {
	ShiyebuReport shiyebuReport = shiyebuReportMap.get(shiyebu.getId());	
%>
			<td colspan="2" style="text-align:center;">
				<%=shiyebuReport==null?"&nbsp;":Util.getDisplay(shiyebuReport.getMantimeNeed(),	 "&nbsp;") %>
			</td>
<%
}
%>
		</tr>
		<tr>
			<td colspan="4" style="text-align:center;" class="td3">
			实际参加岗检人次数
			</td>
<%
for (Department1 shiyebu: shiyebuList.values()) {
	ShiyebuReport shiyebuReport = shiyebuReportMap.get(shiyebu.getId());
%>
			<td colspan="2" style="text-align:center;" >
				<%=shiyebuReport!= null? Util.getDisplay(shiyebuReport.getMantimeReal(), "&nbsp;"):"&nbsp;" %>
			</td>
<%
}
%>
		</tr>
		<tr>
			<td colspan="4" style="text-align:center;" class="td3">
			应岗检单元总数
			</td>
<%
for (Department1 shiyebu: shiyebuList.values()) {
	ShiyebuReport shiyebuReport = shiyebuReportMap.get(shiyebu.getId());
%>
			<td colspan="2" style="text-align:center;">
				<%=shiyebuReport!= null? Util.getDisplay(shiyebuReport.getCheckUnitCountNeed(), "&nbsp;"):"&nbsp;" %>
			</td>
<%
}
%>
		</tr>
		<tr>
			<td colspan="4" style="text-align:center;" class="td3">
			实际岗检单元总数
			</td>
<%
for (Department1 shiyebu: shiyebuList.values()) {
	ShiyebuReport shiyebuReport = shiyebuReportMap.get(shiyebu.getId());
%>
			<td colspan="2" style="text-align:center;">
				<%=shiyebuReport!= null? Util.getDisplay(shiyebuReport.getCheckUnitCountReal(), "&nbsp;"):"&nbsp;" %>
			</td>
<%
}
%>
		</tr>
		<tr>
			<td colspan="4" style="text-align:center;" class="td3">
			被查处“三违”现象次数
			</td>
<%
for (Department1 shiyebu: shiyebuList.values()) {
	ShiyebuReport shiyebuReport = shiyebuReportMap.get(shiyebu.getId());
%>
			<td colspan="2" style="text-align:center;">
				<%=shiyebuReport!= null? Util.getDisplay(shiyebuReport.getIsSanweiCount(), "&nbsp;"):"&nbsp;" %>
			</td>
<%
}
%>

<%
Map<Long, PostCheck> postcheckList = report.getPostcheckList();
%>
		</tr>
		<tr>
			<td rowspan="<%=postcheckList.size() * 2 +2 %>" style="text-align:center;" class="td3" width="60">
			查出问题数
			</td>
			<td colspan="3" style="text-align:center;" class="td3" width="180">
			公司查出问题总数
			</td>
<%
for (Department1 shiyebu: shiyebuList.values()) {
	ShiyebuReport shiyebuReport = shiyebuReportMap.get(shiyebu.getId());
%>
			<td colspan="2" style="text-align:center;">
				<%=shiyebuReport!= null? Util.getDisplay(shiyebuReport.getCorpProblemCount(), "&nbsp;"):"&nbsp;" %>
			</td>
<%
}
%>			
		</tr>
		<tr>
			<td colspan="3" style="text-align:center;" class="td3">
			作业部整改问题总数
			</td>
<%
for (Department1 shiyebu: shiyebuList.values()) {
	ShiyebuReport shiyebuReport = shiyebuReportMap.get(shiyebu.getId());
%>
			<td colspan="2" style="text-align:center;">
				<%=shiyebuReport!= null? Util.getDisplay(shiyebuReport.getIsClosedCount(), "&nbsp;"):"&nbsp;" %>
			</td>
<%
}
%>		
		</tr>
<%
for (PostCheck postcheck : postcheckList.values()) {
%>
		<tr>
			<td rowspan="2" style="text-align:center;" class="td3" width="60">
			<%=postcheck.getCheckName() %>
			</td>
			<td style="text-align:center;" class="td3" width="60">
			处室检查
			</td>
			<td style="text-align:center;" class="td3" width="60">
			检查扣分
			</td>
<%
for (Department1 shiyebu: shiyebuList.values()) {
	ShiyebuReport shiyebuReport = shiyebuReportMap.get(shiyebu.getId());
	if (shiyebuReport != null ) {
		ShiyebuReportCell problemCountCell = shiyebuReport.getProblemCountMap().get(postcheck.getId());
%>
			<td style="text-align:center;" width="30">
				<%=problemCountCell!= null? Util.getDisplay(problemCountCell.getChushiCheckCount(), "&nbsp;"):"&nbsp;" %>
			</td>
			<td style="text-align:center;" width="30">
				<%=problemCountCell!= null? Util.getDisplay(problemCountCell.getChushiCheckGrade() == null ? null: Util.formatGrade(problemCountCell.getChushiCheckGrade()), "&nbsp;"):"&nbsp;" %>
			</td>
<%
	} else {
%>
			<td style="text-align:center;" class="td3" width="30">
				&nbsp;
			</td>
			<td style="text-align:center;" class="td3" width="30">
				&nbsp;
			</td>
<%
	}
}
%>	
		</tr>
		<tr>
			<td style="text-align:center;" class="td3">
			作业部自查
			</td>
			<td style="text-align:center;" class="td3">
			检查扣分
			</td>
<%
for (Department1 shiyebu: shiyebuList.values()) {
	ShiyebuReport shiyebuReport = shiyebuReportMap.get(shiyebu.getId());
	if (shiyebuReport != null ) {
		ShiyebuReportCell problemCountCell = shiyebuReport.getProblemCountMap().get(postcheck.getId());
%>
			<td style="text-align:center;">
				<%=problemCountCell!= null? Util.getDisplay(problemCountCell.getSelfCheckCount(), "&nbsp;"):"&nbsp;" %>
			</td>
			<td style="text-align:center;">
				<%=problemCountCell!= null? Util.getDisplay(problemCountCell.getSelfcheckedGrade()==null?null:Util.formatGrade(problemCountCell.getSelfcheckedGrade()), "&nbsp;"):"&nbsp;" %>
			</td>
<%
	} else {
%>
			<td style="text-align:center;" class="td3">
				&nbsp;
			</td>
			<td style="text-align:center;" class="td3">
				&nbsp;
			</td>
<%
	}
}
%>
		</tr>
<%
}
%>
		<tr>
			<td colspan="4" style="text-align:center;" class="td3">
			日岗检计划完成率
			</td>
<%
for (Department1 shiyebu: shiyebuList.values()) {
	ShiyebuReport shiyebuReport = shiyebuReportMap.get(shiyebu.getId());
%>
			<td colspan="2" style="text-align:center;">
				<%=shiyebuReport!= null? Util.getDisplay(shiyebuReport.getDailyFinishRate() == null? null: Util.formatRate(shiyebuReport.getDailyFinishRate()), "&nbsp;"):"&nbsp;" %>
			</td>
<%
}
%>
		</tr>
		<tr>
			<td colspan="4" style="text-align:center;" class="td3">
			日岗检工作参与度
			</td>
<%
for (Department1 shiyebu: shiyebuList.values()) {
	ShiyebuReport shiyebuReport = shiyebuReportMap.get(shiyebu.getId());
%>
			<td colspan="2" style="text-align:center;">
				<%=shiyebuReport!= null? Util.getDisplay(shiyebuReport.getDailyPartakeRate() == null? null: Util.formatRate(shiyebuReport.getDailyPartakeRate()), "&nbsp;"):"&nbsp;" %>
			</td>
<%
}
%>
		</tr>
		<tr>
			<td rowspan="7" style="text-align:center;" class="td3">
			日岗检问题覆盖面
			</td>
			<td colspan="3" style="text-align:center;" class="td3">
			岗检问题整改率
			</td>
<%
for (Department1 shiyebu: shiyebuList.values()) {
	ShiyebuReport shiyebuReport = shiyebuReportMap.get(shiyebu.getId());
%>
			<td colspan="2" style="text-align:center;">
				<%=shiyebuReport!= null? Util.getDisplay(shiyebuReport.getClosedRate() == null? null: Util.formatRate(shiyebuReport.getClosedRate()), "&nbsp;"):"&nbsp;" %>
			</td>
<%
}
%>
		</tr>
		<tr>
			<td colspan="3" style="text-align:center;" class="td3">
			检查与自查总数对比
			</td>
<%
for (Department1 shiyebu: shiyebuList.values()) {
	ShiyebuReport shiyebuReport = shiyebuReportMap.get(shiyebu.getId());
%>
			<td colspan="2" style="text-align:center;">
				<%=shiyebuReport!= null? Util.getDisplay(shiyebuReport.getSlefCheckRate() == null? null: Util.formatRate(shiyebuReport.getSlefCheckRate()), "&nbsp;"):"&nbsp;" %>
			</td>
<%
}
%>
		</tr>
<%
Map<Long, PostCheck> bigPostcheckMap = new LinkedHashMap<Long, PostCheck>();
for(Long bigPostcheckID: PostcheckMonthQualityReport.BIG_POSTCHECK_MAPPING.values()) {
	bigPostcheckMap.put(bigPostcheckID, report.getPostcheckList().get(bigPostcheckID));
}

for(PostCheck bigPostcheck : bigPostcheckMap.values()) {
%>
		<tr>
			<td colspan="3" style="text-align:center;" class="td3">
			<%=bigPostcheck.getCheckName() %>
			</td>
<%
	for (Department1 shiyebu: shiyebuList.values()) {
		ShiyebuReport shiyebuReport = shiyebuReportMap.get(shiyebu.getId());
		if(shiyebuReport!=null) {
			Integer bigPostcheckRate = shiyebuReport.getCoverageMap().get(bigPostcheck.getId());
%>
			<td colspan="2" style="text-align:center;">
				<%=Util.getDisplay(bigPostcheckRate==null?null:Util.formatRate(bigPostcheckRate), "&nbsp;") %>
			</td>
<%
		} else {
			%>
			<td colspan="2" style="text-align:center;">
				&nbsp;
			</td>
<%	
		}
	}
%>
		</tr>
<%
}
%>
		<tr>
			<td colspan="4" style="text-align:center;" class="td3">
			 “三违”现象
			</td>
<%
for (Department1 shiyebu: shiyebuList.values()) {
	ShiyebuReport shiyebuReport = shiyebuReportMap.get(shiyebu.getId());
%>
			<td colspan="2" style="text-align:center;">
				<%=shiyebuReport!= null? Util.getDisplay(shiyebuReport.getSanwei()==null?null:Util.formatRate(shiyebuReport.getSanwei()), "&nbsp;"):"&nbsp;" %>
			</td>
<%
}
%>			
		</tr>
		<tr>
			<td colspan="4" style="text-align:center;" class="td3">
			岗检评价得分
			</td>
<%
for (Department1 shiyebu: shiyebuList.values()) {
	ShiyebuReport shiyebuReport = shiyebuReportMap.get(shiyebu.getId());
%>
			<td colspan="2" style="text-align:center;">
				<%=shiyebuReport!= null? Util.getDisplay(shiyebuReport.getAssessGrade()==null?null:Util.formatRate(shiyebuReport.getAssessGrade()), "&nbsp;"):"&nbsp;" %>
			</td>
<%
}
%>			
		</tr>
		<tr>
			<td colspan="4" style="text-align:center;" class="td3">
			汇总统计人
			</td>
			<td colspan="4" style="text-align:center;">
				<%=Util.getDisplay(report.getShiyebuWriteUserName(),"&nbsp;") %>
			</td>
			<td colspan="2" style="text-align:center;" class="td3">
			日期
			</td>
			<td colspan="4" style="text-align:center;">
				<%=Util.getDisplay(report.getShiyebuWriteTime()==null?null:Util.formatDate(report.getShiyebuWriteTime()),"&nbsp;") %>
			</td>
			<td colspan="<%=shiyebuList.size()*2-10 %>" style="text-align:center;">
				&nbsp;
			</td>
		</tr>
	</table>
	<div style = "padding-top:20px;">
			<input type="button" style="margin-left: 45%;" value="保 存" onclick="writeShiyebuQualityReport()" />
			<input type="button" style="margin-left: 30px;" value="取 消" onclick="cancelWrite()" />
	</div>
</div>

<script type="text/javascript">
function createShiyebuParamJSON(){
	var paramJSON = '';	
	$('input:text').each(function(){
		var paramName = "'" + this.name + "'" ;
		var paramValue =  "'" + $(this).attr('value') + "'";
		paramJSON =  paramJSON + "," + paramName + ":" + paramValue;
	});
	
	paramJSON = paramJSON.substring(1);
	paramJSON = '{' + paramJSON + '}';

	return paramJSON;
}

function writeShiyebuQualityReport(){
	var paramJSON = createShiyebuParamJSON();

	if ($.dialog.confirm('您确定保存此报告吗？', function(){
		openWaitingDialog('waitingDialog');
		$.ajax({
			type:'post',
			url:'<%=request.getContextPath()%>/postcheck/report/write_month_quality_process.jsp',
			data:{
				paramJSON: paramJSON
			},
			success:function(data,state,xmlhttp){
				var obj = null;
				try {
					obj = eval('(' + data + ')');
				} catch (e) {
				}
				if (typeof(obj.isSuccess) != 'undefined') {
					closeWaitingDialog('waitingDialog');
					if (obj.isSuccess == 'true') {
						$.dialog('报告填报成功！', function() { loadPageSection('<%=request.getContextPath()%>/postcheck/report/write_month_quality.jsp', 'mainContentDiv', {year: <%=year%>, month: <%=month%>}); });
					} else {
						$.dialog.alert(obj.error);
					}
				}
			}
		});
	}, function(){}));
}
function cancelWrite() {
	loadPageSection('<%=request.getContextPath()%>/postcheck/report/write_month_quality_cancel.jsp', 'mainContentDiv');
}
</script>
<%
}
%>